package service

import (
	"singo/model"
	"singo/serializer"
)

// OrganizationDeleteService 删除组织的服务
type OrganizationDeleteService struct {
}

// OrganizationDelete 删除组织
func (service *OrganizationDeleteService) OrganizationDelete(id string) serializer.Response {
	var organization model.Organization
	err := model.DB.Where("uid = ?", id).First(&organization).Error
	if err != nil {
		return serializer.Response{
			Status: 404,
			Msg:    "组织不存在",
			Error:  err.Error(),
		}
	}

	if err := model.DB.Model(&organization).Where("uid = ?", id).Delete(&organization).Error; err != nil {
		return serializer.ParamErr("删除失败", err)
	}

	return serializer.Response{
		Data:   true,
		Msg:    "成功",
		Status: 0,
	}
}
